<template>
    <div class="adminSet">
        <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <span class="title layui-field-title el-icon-document">活跃度商品配置</span>
            <div class="cellLabel" style="margin-left:-70px">
                <el-form-item prop="goodsId" class="label_edit">
                    <span>商品选择</span>
                    <el-select v-model="ruleForm.goodsId" placeholder="请选择商品" filterable style="width:80%">
                        <el-option
                            v-for="item in optionsDate"
                            :key="item.goodsId"
                            :label="item.goodsName + '(单位：' + item.unitName + ')'"
                            :value="item.goodsId"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </div>

            <el-form-item>
                <el-button
                    type="primary"
                    style="margin-top:20px;margin-left:20%;"
                    @click="confirmEdit('ruleForm')"
                    size="mini"
                >保存设置</el-button>
                <!-- <el-button type="primary" style="margin-top:20px" @click="goback()" size="mini">返回</el-button> -->
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { queryStockGoods } from "@/api/compositegoods";
import {
  queryActivationGoods,
  updateActivationGoods
} from "@/api/integralrule";
import qs from "qs";

export default {
  data() {
    return {
      ruleForm: {
        goodsId: "",
        uuid: ""
      },
      optionsDate: []
    };
  },

  mounted() {
    this.logininfo = localStorage.getItem("logininfo");
    this.orgSeq = JSON.parse(this.logininfo).orgSeq;
    this.getUserWhiteList(); //获取当前配置商品信息
    this.queryActivationGoods(); //
  },

  methods: {
    //获取当前配置商品信息
    getUserWhiteList() {
      let data = {
        size: 99999,
        current: 1,
        condition: {
          isMinUnit: 1,
          status: 1
        },
        ascs: [],
        descs: []
      };
      queryStockGoods(data).then(res => {
        this.optionsDate = res.records;
      });
    },
    queryActivationGoods() {
      queryActivationGoods().then(res => {
        this.ruleForm.uuid = res.result.uuid;
        this.ruleForm.goodsId = res.result.goodsId;
      });
    },
    // goback() {
    //   this.$router.go("-1");
    // },
    //保存积分规则
    confirmEdit() {
      let data = {
        goodsId: this.ruleForm.goodsId
      };
      updateActivationGoods(data).then(res => {
        this.$message({
          showClose: true,
          message: res.message,
          type: "success"
        });
      });
    }
  }
};
</script>
<style lang="less" scoped>
.title {
    display: block;
    margin-left: -2%;
    margin-top: 30px;
    margin-bottom: 30px;
    font-size: 18px;
    color: #666 !important;
    border-style: solid;
}

.layui-field-title {
    border-width: 0px 0 0;
}

.label_edit {
    margin-left: -15px;
}
.cellLabel {
    margin-left: -80px;
}
.adminSet {
    border: 1px solid #ebeef5;
    margin-left: 150px;
    padding: 8px 0px 20px 180px;
    width: 54%;
}
</style>
